package com.probiz.estore.exports.handler.product;

import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;

import com.probiz.estore.catalog.service.ProductCategoryManager;
import com.probiz.estore.common.model.catalog.ProductCategory;
import com.probiz.estore.common.model.product.Product;
import com.probiz.estore.exports.handler.ColumnHandler;
import com.probiz.estore.exports.model.Column;


public class CategorySimplePathNameHandler implements ColumnHandler{
	private ProductCategoryManager productCategoryManager = null;
	
	public void setProductCategoryManager(
			ProductCategoryManager productCategoryManager) {
		this.productCategoryManager = productCategoryManager;
	}

	public String getProperty(Object target, Column column, HSSFSheet sheet, HSSFRow row, List<String> listHeader){
		Product product = (Product)target;
		if(product.getCategoryId() != null){
			List<ProductCategory> pc = productCategoryManager.getNavigationCategories(product.getCategoryId());
			StringBuffer sb = new StringBuffer("");
			for (int i=0;i<pc.size();i++) {
				if(i == (pc.size()-1)){
					sb.append(pc.get(i).getCategoryName());
				} else { 
					sb.append(pc.get(i).getCategoryName()).append(">");
				}
			}
			return sb.toString();
		}
		return null;
	}
}
